package Sep.FiveTree;

import java.util.List;
import java.util.ArrayList;

public class Five{
    public static void main(String[] args) {
        System.out.println("ddddddd");
    }
}

// 113. 路径总和 II
class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode(int x) { val = x; }
  }
 
class Solution {
    List<List<Integer>> ans = new ArrayList<>();
    public List<List<Integer>> pathSum(TreeNode root, int sum) {
        search(root, sum, new ArrayList<>());
        return ans;
    }

    public void search(TreeNode root,int sum,List<Integer>tmp){
        if(root==null) return;
        tmp.add(root.val);
        if(sum-root.val==0&&root.left==null&&root.right==null)ans.add(new ArrayList<>(tmp));
        search(root.left, sum-root.val, tmp);
        search(root.right, sum-root.val, tmp);
        tmp.remove(tmp.size());
    }
}

